<?php
require_once 'Sabai/Model/PageNavigator.php';

class Sabai_Model_PageNavigatorRemote extends Sabai_Model_PageNavigator
{
    var $_update;
    var $_ajaxUrl;

    function Sabai_Model_PageNavigatorRemote($update, &$pages, $currentPage, $linkUrl, $ajaxUrl = null, $pageVar = 'page', $pageSummaryText = null)
    {
        $this->_update = $update;
        $this->_ajaxUrl = array_merge(array('base' => '',
                                            'params' => array(),
                                            'fragment' => ''),
                                      !isset($ajaxUrl) ? $linkUrl : $ajaxUrl);
        parent::Sabai_Model_PageNavigator($pages, $currentPage, $linkUrl, $pageVar, $pageSummaryText);
    }

    function _getFirstPageLink()
    {
        return create_link_to_remote('&laquo;', $this->_update, array('base' => $this->_linkUrl['base'], 'params' => array_merge($this->_linkUrl['params'], array($this->_pageVar => 1)), 'fragment' => $this->_linkUrl['fragment']), array('base' => $this->_ajaxUrl['base'], 'params' => array_merge($this->_ajaxUrl['params'], array($this->_pageVar => 1))));
    }

    function _getPreviousPageLink()
    {
        return create_link_to_remote('&lsaquo;', $this->_update, array('base' => $this->_linkUrl['base'], 'params' => array_merge($this->_linkUrl['params'], array($this->_pageVar => $this->_currentPage - 1)), 'fragment' => $this->_linkUrl['fragment']), array('base' => $this->_ajaxUrl['base'], 'params' => array_merge($this->_ajaxUrl['params'], array($this->_pageVar => $this->_currentPage - 1))));
    }

    function _getPageLink($pageNum)
    {
        return create_link_to_remote($pageNum, $this->_update, array('base' => $this->_linkUrl['base'], 'params' => array_merge($this->_linkUrl['params'], array($this->_pageVar => $pageNum)), 'fragment' => $this->_linkUrl['fragment']), array('base' => $this->_ajaxUrl['base'], 'params' => array_merge($this->_ajaxUrl['params'], array($this->_pageVar => $pageNum))));
    }

    function _getNextPageLink()
    {
        return create_link_to_remote('&rsaquo;', $this->_update, array('base' => $this->_linkUrl['base'], 'params' => array_merge($this->_linkUrl['params'], array($this->_pageVar => $this->_currentPage + 1)), 'fragment' => $this->_linkUrl['fragment']), array('base' => $this->_ajaxUrl['base'], 'params' => array_merge($this->_ajaxUrl['params'], array($this->_pageVar => $this->_currentPage + 1))));
    }

    function _getLastPageLink()
    {
        return create_link_to_remote('&raquo;', $this->_update, array('base' => $this->_linkUrl['base'], 'params' => array_merge($this->_linkUrl['params'], array($this->_pageVar => $this->_pages->size())), 'fragment' => $this->_linkUrl['fragment']), array('base' => $this->_ajaxUrl['base'], 'params' => array_merge($this->_ajaxUrl['params'], array($this->_pageVar => $this->_pages->size()))));
    }
}